home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 25 / CU Amiga Magazine's Super CD-ROM 25 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-08].iso / CUCD / Programming / GMS / GMSDev / Source / C / Blitter / BounceLine.c next >
Encoding:
C/C++ Source or Header  |  1998-05-14  |  2.0 KB  |  85 lines

  1. /* Dice: 1> dcc -l0 -mD dpk.o BounceLine.c -o BounceLine
  2. **
  3. ** Line bouncing demo that works on a screen of any type of dimensions as
  4. ** specified by the user in GMSPrefs.
  5. */
  6.  
  7. #include <proto/dpkernel.h>
  8.  
  9. BYTE *ProgName      = "Bounce Line";
  10. BYTE *ProgAuthor    = "Paul Manias";
  11. BYTE *ProgDate      = "May 1998";
  12. BYTE *ProgCopyright = "DreamWorld Productions (c) 1996-1998.  Freely distributable.";
  13. BYTE *ProgShort     = "Line bouncing demo.";
  14.  
  15. void main(void)
  16. {
  17.   struct GScreen *Screen;
  18.   struct JoyData *JoyData;
  19.   LONG palette[] = { PALETTE_ARRAY, 2, 0x000000L, 0x80f0f0L };
  20.   int  sx,sy,ex,ey;
  21.   int  dsx,dsy,dex,dey;
  22.  
  23.   if (Screen = InitTags(NULL,
  24.       TAGS_SCREEN,    NULL,
  25.         GSA_BitmapTags, NULL,
  26.         BMA_Palette,    palette,
  27.         TAGEND,         NULL,
  28.       GSA_Attrib,     SCR_DBLBUFFER,
  29.       TAGEND)) {
  30.  
  31.      sx = SlowRandom(Screen->Width);  dsx = -1;
  32.      sy = SlowRandom(Screen->Height); dsy = 2;
  33.      ex = SlowRandom(Screen->Width);  dex = 3;
  34.      ey = SlowRandom(Screen->Height); dey = 1;
  35.  
  36.      if (JoyData = Init(Get(ID_JOYDATA),NULL)) {
  37.  
  38.         Display(Screen);
  39.  
  40.         do
  41.         {
  42.           Clear(Screen->Bitmap);
  43.           Query(JoyData);
  44.           sx += dsx;
  45.           sy += dsy;
  46.           ex += dex;
  47.           ey += dey;
  48.  
  49.           if(sx<0) { sx = 0; dsx = -(dsx); }
  50.           if(sy<0) { sy = 0; dsy = -(dsy); }
  51.           if(ex<0) { ex = 0; dex = -(dex); }
  52.           if(ey<0) { ey = 0; dey = -(dey); }
  53.  
  54.           if(sx>Screen->Width-1) {
  55.             sx  = Screen->Width-1;
  56.             dsx = -(dsx);
  57.           }
  58.  
  59.           if(sy>Screen->Height-1) {
  60.             sy  = Screen->Height-1;
  61.             dsy = -(dsy);
  62.           }
  63.  
  64.           if(ex>Screen->Width-1) {
  65.             ex  = Screen->Width-1;
  66.             dex = -(dex);
  67.           }
  68.  
  69.           if(ey>Screen->Height-1) {
  70.             ey  = Screen->Height-1;
  71.             dey = -(dey);
  72.           }
  73.  
  74.           DrawUCLine(Screen->Bitmap,sx,sy,ex,ey,1,0xffffffff);
  75.           WaitAVBL();
  76.           SwapBuffers(Screen);
  77.         } while (!(JoyData->Buttons & JD_LMB));
  78.  
  79.      Free(JoyData);
  80.      }
  81.   Free(Screen);
  82.   }
  83. }
  84.  
  85.